/**
 *
 * Copyright by Samuel Castro & Joaquim Fonseca, 2011
 * All Rights Reserved
 *
 * NOTES:
 * Please do not redistribute this plugin without my permission
 * Plugin made for private use only
 *
 */
package com.SySammy.SdCurrency.Handlers;

import com.SySammy.SdCurrency.Prop.CurrencyProperties;
import com.SySammy.SdCurrency.sdC;
import org.bukkit.ChatColor;

public class RepeatingTask implements Runnable {

    BankHandler BH = new BankHandler();
    String s;
    sdC plugin;

    public RepeatingTask(String s, sdC plugin) {
        this.s = s;
        this.plugin = plugin;
    }

    @Override
    public void run() {
        try {
            if (BH.GetloanTimeLeft(s) >= 0) {
                BH.SetTimeLeft(s, BH.GetloanTimeLeft(s) - CurrencyProperties.ScheduleRepTime);
                if (BH.GetloanTimeLeft(s) >= 24) {
                    plugin.getServer().getPlayer(s).sendMessage(ChatColor.DARK_AQUA + "Don't forget to pay your bank!!!");
                    plugin.getServer().getPlayer(s).sendMessage(ChatColor.RED + "DeadLine: " + ChatColor.GOLD + BH.GetloanTimeLeft(s) / 24 + " Day(s)" + ChatColor.RED + " [Updated every: " + CurrencyProperties.ScheduleRepTime + " hour(s)]");
                    return;
                } else {
                    plugin.getServer().getPlayer(s).sendMessage(ChatColor.DARK_AQUA + "Don't forget to pay your bank!!!");
                    plugin.getServer().getPlayer(s).sendMessage(ChatColor.RED + "DeadLine: " + ChatColor.GOLD + BH.GetloanTimeLeft(s) + " Hour(s)" + ChatColor.RED + " [Updated every: " + CurrencyProperties.ScheduleRepTime + " hour(s)]");
                    return;
                }
            }
        } catch (Exception e) {
        }
    }
}
